/**
 * 外层ul的样样式表为如下
 * <ul class="pagination pull-right" id="pagination">
 </ul>
 */
function macpage(currentpage,totalPages,initGrid){
    var pagehtml="";
    var dot = '<li><a href="javascript:void(0)">...</a></li>';
    //url
    var prev = currentpage-1>1?currentpage-1:1;
    var next = currentpage < totalPages?currentpage+1:totalPages;

    pagehtml+='<li><a href="javascript:void(0);" onclick="initGrid(1)">首页</a></li>'+
        '<li><a href="javascript:void(0);" onclick="initGrid('+prev+')">上一页</a></li>';
    if(totalPages<=8){
        for(var i=1;i<=totalPages;i++){
            if(currentpage == i){
                pagehtml+='<li ><a href="javascript:void(0);" onclick="initGrid('+i+')" style="background: #ed9c28">'+i+'</a></li>';
            }else{
                pagehtml+='<li><a href="javascript:void(0);" onclick="initGrid('+i+')">'+i+'</a></li>';
            }

        }
    }else{
        if(currentpage < 5){
            for(var i=1;i<=7;i++){
                if(currentpage == i){
                    pagehtml+='<li ><a href="javascript:void(0);" onclick="initGrid('+i+')" style="background: #ed9c28">'+i+'</a></li>';
                }else{
                    pagehtml+='<li ><a href="javascript:void(0);" onclick="initGrid('+i+')">'+i+'</a></li>';
                }
            }
            pagehtml+=dot;
        }else{
            pagehtml+='<li ><a href="javascript:void(0);" onclick="initGrid(1)">'+1+'</a></li>';
            pagehtml+='<li ><a href="javascript:void(0);" onclick="initGrid(2)">'+2+'</a></li>';
            pagehtml+=dot;

            var begin = currentpage - 2;
            var end = currentpage + 2;
            if(end > totalPages){
                end = totalPages;
                begin = end - 4;
                if(currentpage - begin < 2){
                    begin = begin-1;
                }
            }else if(end + 1 == totalPages){
                end = totalPages;
            }
            for(var i=begin;i<=end;i++){
                if(currentpage == i){
                    pagehtml+='<li ><a href="javascript:void(0);" onclick="initGrid('+i+')" style="background: #ed9c28">'+i+'</a></li>';
                }else{
                    pagehtml+='<li ><a href="javascript:void(0);" onclick="initGrid('+i+')">'+i+'</a></li>';
                }
            }
            if(end != totalPages){
                pagehtml += dot;
            }

        }
    }
    pagehtml+='<li><a href="javascript:void(0);" onclick="initGrid('+next+')">下一页</a></li>'+
        '<li><a href="javascript:void(0);" onclick="initGrid('+totalPages+')">尾页</a></li>';
    return pagehtml;
}